package swu.edu.cn.javaee.controller;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import swu.edu.cn.javaee.entity.Gmember;
import swu.edu.cn.javaee.entity.GmemberInfo;
import swu.edu.cn.javaee.entity.GroupInfo;
import swu.edu.cn.javaee.service.GmemberService;
import static swu.edu.cn.javaee.component.Signal.*;
@Controller
//解决跨域问题：允许所有源域名访问
@CrossOrigin(origins = "*")
public class GmemberController {

    @Resource
    private GmemberService gmemberService;



    //加入群组
    @RequestMapping("/saveGmember")
    @ResponseBody
    public String saveGmember(String gid,String uid,String gnickname){
        String result=gmemberService.saveGmember(gid,uid,gnickname);
        if (result!=null){
            return result;
        }
        else {
            return FAILED_CODE_JOIN;
        }
    }

    //显示全体群成员
    @RequestMapping("/queryGmemberList")
    @ResponseBody
    public GmemberInfo queryGmemberList(String gid){
        GmemberInfo result=gmemberService.queryGmemberList(gid);
        if (result!=null){
            return result;
        }
        else {
            return null;
        }
    }

    //根据id查找群员
    @RequestMapping("/queryMemberById")
    @ResponseBody
    public Gmember queryMemberById(String uid,String gid){
        Gmember result=gmemberService.queryMemberById(uid, gid);
        if (result!=null){
            return result;
        }
        else {
            return null;
        }
    }

    //删除群员
    @RequestMapping("/deleteMember")
    @ResponseBody
    public String deleteMember(String uid,String gid){
        String result=gmemberService.deleteMember(uid, gid);
        return result;
    }

}
